package cn.francis.common.exception;

import lombok.Getter;

import java.io.Serial;

/**
 * 业务异常
 *
 * @author 张俊辉
 */

@Getter
public class BusinessException extends RuntimeException {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private String code;

    /**
     * 错误提示
     */
    private String message;

    /**
     * 错误明细，内部调试错误
     */
    private String detailMessage;

    /**
     * 空构造器，避免反序列化问题
     */
    public BusinessException() {
        super();
    }

    /**
     * 最常用构造函数：只传用户提示信息
     */
    public BusinessException(String message) {
        super(message);
        this.code = "BIZ_ERROR";
        this.message = message;
        this.detailMessage = null;
    }

    /**
     * 构造函数：传错误码和用户提示信息
     */
    public BusinessException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
        this.detailMessage = null;
    }

    /**
     * 构造函数：传错误码、用户提示、内部错误信息
     */
    public BusinessException(String code, String message, String detailMessage) {
        super(message);
        this.code = code;
        this.message = message;
        this.detailMessage = detailMessage;
    }

    /**
     * 构造函数：传错误码、用户提示、原始异常
     */
    public BusinessException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
        this.detailMessage = cause != null ? cause.getMessage() : null;
    }
}
